#include <bits/stdc++.h>
using namespace std;
int p[10005];
int cnt;
struct Node{
     int d;
     int v;
     int a;
}car[10005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    int n,m,l,v;
    while(T--){
        cin >> n >> m >> l >> v;
        for(int i=1;i<=n;i++){
            cin >> car[i].d >> car[i].v >> car[i].a;
        }
        for(int i=1;i<=m;i++) cin >> p[i];
        for(int i=1;i<=n;i++){
            if(car[i].a==0){
                if(car[i].v>v)  cnt++;
            }
        }
        cout << cnt << ' ' << m-1;
    }
    return 0;
}
